$(function() {
    document.onkeydown=function(event){
        var e = event || window.event || arguments.callee.caller.arguments[0];
        if(e && e.keyCode==13){ // 按向下键
        	addPPublisher();
        }
    }; 
    $.divselect("#divselect_p_level", "#p_levelId");
});

var toAddPContact = function(){
	$.box('.onlyuserforaddtaskalertbox', {
		onOpen : function() {
			/*$('#scrollbar').tinyscrollbar();
			$('#scrollbar_002').tinyscrollbar();//里面有2个滚动条*/			
		}
	}, {
		submit:{
			close:false,
			dom:['#submitTaskBtn'],
			fun:function(index){
				addPPublisher();
			}
		},
		close : {
			dom : [ '.onlyuserforaddtaskalertbox .closeforaddtask','.onlyuserforaddtaskalertbox .c_but_no' ]
		}
	});
};

var addPPublisher = function(){
	var fun = function(msg) {
		if (msg.result == "success") {
			layer.msg("新建客户成功！",1,9,function(){
				window.location.href=globePath+"/publishMange/listAjax."+action;
			});
		} else {
			layer.alert(msg.result);
		}
	};
	
	var name = $.trim($("#name").val());
	if(name==''){
		layer.msg("客户全称不能为空");
		return false;
	}
	
	var simpleName = $.trim($("#simpleName").val());
	if(simpleName==''){
		layer.msg("客户简称不能为空");
		return false;
	}
	var contactName = $.trim($("#contactName").val());
	if(contactName==''){
		layer.msg("联系人不能为空");
		return false;
	}
	
	var contactPhone = $.trim($("#contactPhone").val());
	if(contactPhone==''){
		layer.msg("手机号码不能为空!");
		return false;
	}
	
	if(!isMobile(contactPhone)){
		layer.msg("手机号码格式不正确!");
		return false;
	}
	
	var userId = $.trim($("#userId").val());
	if(userId==''){
		layer.msg("销售代表不能为空");
		return false;
	}
	ajaxCommFunWithDataType(globePath+"/publishMange/submitPPublisher"+action, $("#addPPublisherForm").serialize(),'json',fun);
};